/**
  ******************************************************************************
  * @file 	zmotors.h 
  * @brief  header file 
  ******************************************************************************
  */

#ifndef __ZBMOTORS_H
#define __ZBMOTORS_H

#include "main.h"

// general defines
#define chNone 	0x00
#define ch1 	0x01
#define ch2 	0x02
#define ch3 	0x04
#define ch4 	0x08
#define chAll 	0x0F

#define init 		0x01
#define disable 	0x02
#define newFQ 		0x03
#define newDuty 	0x04

// defines motor A 
#define PWMA_TIM 		TIM3
#define PWMA_PB1 		RCC_APB1Periph_TIM3
#define PWMA_PAB2 		RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO
#define PWMA_S0			GPIO_Pin_6
#define PWMA_S1   		GPIO_Pin_7
#define PWMA_S2			GPIO_Pin_0
#define PWMA_S3   		GPIO_Pin_1
#define PWMA_PORT1		GPIOA
#define PWMA_PORT2		GPIOB



void initPWM1(void);
void initPWM1GPIO(void);
void updatePWM1(void);
void setupPWM(TIM_TypeDef * timer, float frequency, u8 duty[4], u8 channels, u8 newState);

// utility functions
u16 frequencyToPeriod(float frequency, u16 *prescalar);
u16 dutyCycleToPulse(u8 duty, u16 period);

#endif
